function out = regressMacroOnSlope(data,shortRate,maturities,regime_2,econAct,h)

T             = size(data,1);
n             = length(maturities);
beta          = nan(2,n);
R2            = nan(1,n);
beta_tstat    = nan(2,n);
startMat      = find(maturities >= 2*12);
for i=startMat:n
   Y              = econAct(1+h:T,1);
   x              = data(1:T-h,i)-shortRate(1:T-h,1);
   X              = [ones(T-h,1) x];
   results        = nwest(Y,X,3);
   beta(:,i)      = results.beta;           
   R2(1,i)        = results.rsqr;
   beta_tstat(:,i)= results.tstat;
end

% With regime switching
betaRegime         = nan(4,n);
R2regime           = nan(1,n);
betaRegime_tstat   = nan(4,n);
for i=startMat:n
   Y               = econAct(1+h:T,1);
   x               = data(1:T-h,i)-shortRate(1:T-h,1);
   X               = [ones(T-h,1) x ...
                      regime_2(1:T-h) regime_2(1:T-h).*x  ];
   results              = nwest(Y,X,3);
   betaRegime(:,i)      = results.beta;
   R2regime(1,i)        = results.rsqr;
   betaRegime_tstat(:,i)= results.tstat;
end

% Saving the results
out.beta             = beta;
out.R2               = R2;
out.beta_tstat       = beta_tstat;
out.betaRegime       = betaRegime;
out.R2regime         = R2regime;
out.betaRegime_tstat = betaRegime_tstat;
out.maturities       = maturities;

end